﻿#region Using Directives

    using System;
    using System.Linq;
    using System.Collections.Generic;

    using Csla;

    using MarketPulse.BusinessLogic.Core;
    using MarketPulse.Reporting.Core.Criteria;

#endregion

namespace MarketPulse.Reporting.Core
{
    /// <summary>
    /// This class represents a collection of Reporting Periods
    /// </summary>
    [Serializable]
    [Csla.Server.ObjectFactory("MarketPulse.DataAccess.Factory.ReportingLevelFactory, MarketPulse.DataAccess.Factory", "FetchInfoList")]
    public class ReportingLevelInfoList : MarketPulseReadOnlyListBase<ReportingLevelInfoList, ReportingLevelInfo>
    {       

        #region Constructors

            /// <summary>
            /// Default constructor is private in order to (try to) enforce construction
            /// only via the static factory methods provided.
            /// </summary>
            private ReportingLevelInfoList()
            {
            }

        #endregion

        #region Methods

            #region Factory Methods

                /// <summary>
                /// Method used to get a read only list of read only ReportingPeriods that are associated with a particular Client (via the DataPortal client proxy)
                /// </summary>
                /// <param name="clientGUID">The GUID of the Client used to retrieve the list</param>
                /// <param name="profileGUID">The GUID of the Profile used to retrieve the list</param>
                /// <returns>A populated read only list of read only ReportingPeriods</returns>
                public static ReportingLevelInfoList GetByClientGUIDAndProfileGUID(Guid clientGUID, Guid profileGUID)
                {
                    return DataPortal.Fetch<ReportingLevelInfoList>(new ClientGUIDAndProfileGUIDCriteria(clientGUID, profileGUID));
                }

                /// <summary>
                /// Method used to get a read only list of read only ReportingPeriods that are associated with a particular Client (via the DataPortal client proxy)
                /// </summary>
                /// <param name="clientGUID">The GUID of the Client used to retrieve the list</param>
                /// <returns>A populated read only list of read only ReportingPeriods</returns>
                public static ReportingLevelInfoList GetByClientGUID(Guid clientGUID)
                {
                    return DataPortal.Fetch<ReportingLevelInfoList>(new SingleCriteria<Guid>(clientGUID));
                }

            #endregion

            #region Helper Methods

                /// <summary>
                /// Deselects all ReportingLevelInfo objects in this List.
                /// </summary>
                public void DeselectAll()
                {
                    this.Items.All(rl => { rl.Selected = false; return true; });
                }

            #endregion

        #endregion

        #region Properties

            /// <summary>
            /// Returns a comma-delimited list of selected BranchGUIDs.
            /// </summary>
            /// <returns>Returns a comma-delimited list of selected BranchGUIDs.</returns>
            public List<Guid> SelectedBranches
            {
                get
                {
                    return this.Items.Where(rl => rl.Type == ReportingLevelType.Branch && rl.Selected).Select(rl => rl.GUID.Value).ToList();
                }
            }

            /// <summary>
            /// Returns a comma-delimited list of selected CompanyGUIDs.
            /// </summary>
            /// <returns>Returns a comma-delimited list of selected CompanyGUIDs.</returns>
            public List<Guid> SelectedCompanies
            {
                get
                {
                    return this.Items.Where(rl => rl.Type == ReportingLevelType.Company && rl.Selected).Select(rl => rl.GUID.Value).ToList();
                }
            }

        #endregion
    }
}
